package cn.imvc.app.controllers.system;

import java.util.HashSet;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;

import cn.imvc.app.entities.Role;
import cn.imvc.app.models.RoleMenuModel;
import cn.imvc.app.models.RoleModel;
import cn.imvc.core.DialogBean;
import cn.imvc.core.Render;

public class MenuRoleControllerImpl implements MenuRoleController {
	public String roles;
	public int id;
	public String menus;
	public int[] roleid;
	@Autowired
	private RoleMenuModel roleMenuModel;
	@Autowired
	private RoleModel roleModel;
	
	public String index() {
		menus=roleMenuModel.getMenus();
		return "menu-role/index";
	}

	public String show() {
		roles=roleMenuModel.getRoleTree(id);
		return "menu-role/show";
	}

	public String create() {
		Set<Role> roles=new HashSet<Role>();
		if(roleid!=null)
		for (int rid : roleid) {
			roles.add(roleModel.get(rid));
		}
		roleMenuModel.saveMenuRole(id,roles);
		return Render.json(new DialogBean("200", "保存成功","menu-role","closeCurrent"));
	}
}
